<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加载文件</title>
</head>
<body>
    
</body>
</html>

<script>
    //下面是异步加载外部的js文件，需要使用回调执行，并设置的错误处理函数
    // function load(file='',resolve,reject){
    //     const script = document.createElement('script');
    //     script.src = file;
    //     script.onload = resolve;
    //     script.onerror = reject;
    //     document.body.appendChild(script);

    // }
    // load('js/houdunren.js',script => {
    //     console.log(`${script.path[0].src} 加载成功`);
    //     houdunren();
    // },error => {
    //     console.log(`${error.srcElement.src} 加载失败`)
    // })

    


    function load(file,resolve,reject){
        const script = document.createElement('script');
        script.src = file;
        script.onload = resolve;
        script.onerror = reject;
        document.body.appendChild(script);
    }
    
    //如果要加载多个脚本的时候需要使用嵌套使用下面houdurnen.js  依赖hd.js ，需要先加载hd.js 后加载houdunren.js
    load('js/hd.js',script=>{
        load('js/houdunren.js',script=>{
            houdunren();
        },error => {
            console.log(`${error.srcElement.src} 加载失败`);
        });
    },error=>{
        console.log(`${error.srcElement.src} 加载失败`);
    });

    

</script>